refactor(audio): Simplify available audio samples management#2773
refactor(audio): Simplify available audio samples management#2773xezon wants to merge 3 commits into
Conversation
|
| Filename | Overview |
|---|---|
| Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp | Core implementation of the refactor: list→vector, notify calls removed, new getAvailable*Samples() implementations, and corrected freeAllMilesHandles loop. Handle lifecycle (pop_back on acquire, push_back on release) is correctly maintained throughout. |
| Core/GameEngine/Source/Common/Audio/GameSounds.cpp | canPlayNow updated to query getAvailable*Samples() instead of comparing counters; lazy-init of sample counts removed. Logic is equivalent to prior behavior. |
| Core/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h | Declares new getAvailable2DSamples/getAvailable3DSamples overrides and changes member containers from std::list to std::vector. |
| Core/GameEngine/Include/Common/GameAudio.h | Adds pure virtual getAvailable2DSamples() and getAvailable3DSamples() to the AudioManager interface. |
| Core/GameEngine/Include/Common/GameSounds.h | Removes notify callbacks, available-sample helpers, and the two counter member variables from SoundManager. |
Sequence Diagram
sequenceDiagram
participant SM as SoundManager
participant AM as AudioManager
participant MAM as MilesAudioManager
participant Pool as AvailablePool
Note over SM,Pool: canPlayNow check
SM->>AM: getAvailable2DSamples()
AM->>MAM: getAvailable2DSamples()
MAM->>Pool: size()
Pool-->>SM: N handles available
Note over MAM,Pool: Audio starts playing
MAM->>Pool: pop_back via getFirst2DSample
Pool-->>MAM: HSAMPLE handle
MAM->>MAM: playSample(event, handle)
Note over MAM,Pool: Audio stops
MAM->>Pool: push_back via releaseMilesHandles
Pool-->>MAM: handle returned, size increases
Reviews (2): Last reviewed commit: "Fix wrong function call in debug draw" | Re-trigger Greptile
| HSAMPLE retSample = *m_availableSamples.begin(); | ||
| m_availableSamples.erase(m_availableSamples.begin()); | ||
| return (retSample); | ||
| if (!m_availableSamples.empty()) { |
There was a problem hiding this comment.
This gets the last sample in the vector, but the function name says first. Originally it would also get the first sample in the list.
I presume this is for performance (FILO instead of FIFO), but the naming of function and comments - that talk about 'first' are confusing.
| for ( it3D = m_available3DSamples.begin(); it3D != m_available3DSamples.end(); ) { | ||
| std::vector<H3DSAMPLE>::iterator it3D; | ||
| for ( it3D = m_available3DSamples.begin(); it3D != m_available3DSamples.end(); ++it3D ) { | ||
| H3DSAMPLE sample3D = *it3D; |
There was a problem hiding this comment.
Temporary variable not needed I think
AIL_release_3D_sample_handle(*it3D);| std::vector<HSAMPLE>::iterator it; | ||
| for ( it = m_availableSamples.begin(); it != m_availableSamples.end(); ++it ) { | ||
| HSAMPLE sample = *it; | ||
| AIL_release_sample_handle(sample); |
There was a problem hiding this comment.
Temporary variable not needed I think
AIL_release_3D_sample_handle(*it);
This change simplifies the available audio samples management.
Instead of manually counting at various callsites, it now simply calculates the available audio samples from the vectors. The numbers are used mostly for debug purposes, except in
SoundManager::canPlayNow.